﻿<Window Name="sett" x:Class="PlayRandom.Views.SettingsView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:main="clr-namespace:PlayRandom"
        xmlns:conv="clr-namespace:PlayRandom.Converters"
        xmlns:convUtil="clr-namespace:CommonUtilities.Converters;assembly=CommonUtilities"
        xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
        Title="Settings" SizeToContent="WidthAndHeight" ResizeMode="NoResize" MinHeight="275" 
        PreviewKeyDown="sett_PreviewKeyDown" Closing="Window_Closing">
    <Window.Resources>
        <convUtil:VisibilityConverter x:Key="VisibilityConverter" />
        <conv:FriendlyNameConverter x:Key="FriendlyNameConverter" />

        <Style TargetType="CheckBox">
            <Setter Property="Height" Value="Auto" />
            <Setter Property="Margin" Value="2,1.5" />
            <Setter Property="Padding" Value="10,0" />
            <Setter Property="VerticalAlignment" Value="Center" />
            <Setter Property="VerticalContentAlignment" Value="Center" />
        </Style>
        <Style TargetType="Button">
            <Setter Property="Height" Value="23" />
            <Setter Property="Margin" Value="2,0" />
            <Setter Property="Padding" Value="10,0" />
            <Setter Property="VerticalAlignment" Value="Center" />
            <Setter Property="VerticalContentAlignment" Value="Center" />
        </Style>
        <Style TargetType="ComboBox">
            <Setter Property="Height" Value="23" />
            <Setter Property="Margin" Value="2,0" />
            <Setter Property="Padding" Value="10,0" />
            <Setter Property="VerticalAlignment" Value="Center" />
            <Setter Property="VerticalContentAlignment" Value="Center" />
        </Style>
        <Style TargetType="ToggleButton">
            <Setter Property="Height" Value="23" />
            <Setter Property="Margin" Value="2,0" />
            <Setter Property="Padding" Value="10,0" />
            <Setter Property="VerticalAlignment" Value="Center" />
            <Setter Property="VerticalContentAlignment" Value="Center" />
        </Style>

        <Style x:Key="ToggleDisplayViewStyle" TargetType="ToggleButton">
            <Style.Triggers>
                <Trigger Property="IsChecked" Value="True">
                    <Setter Property="Content">
                        <Setter.Value>
                            <Grid>
                                <UniformGrid Rows="3" Columns="3">
                                    <UniformGrid.Resources>
                                        <Style x:Key="SquareStyle" TargetType="Rectangle">
                                            <Setter Property="Height" Value="5" />
                                            <Setter Property="Width" Value="5" />
                                            <Setter Property="Fill" Value="Black" />
                                            <Setter Property="Margin" Value="1" />
                                        </Style>
                                    </UniformGrid.Resources>
                                    <Rectangle Style="{DynamicResource SquareStyle}" />
                                    <Rectangle Style="{DynamicResource SquareStyle}" />
                                    <Rectangle Style="{DynamicResource SquareStyle}" />
                                    <Rectangle Style="{DynamicResource SquareStyle}" />
                                    <Rectangle Style="{DynamicResource SquareStyle}" />
                                    <Rectangle Style="{DynamicResource SquareStyle}" />
                                    <Rectangle Style="{DynamicResource SquareStyle}" />
                                    <Rectangle Style="{DynamicResource SquareStyle}" />
                                    <Rectangle Style="{DynamicResource SquareStyle}" />
                                </UniformGrid>
                            </Grid>
                        </Setter.Value>
                    </Setter>
                </Trigger>
                <Trigger Property="IsChecked" Value="False">
                    <Setter Property="Content">
                        <Setter.Value>
                            <Grid>
                                <UniformGrid Rows="3" Columns="3">
                                    <UniformGrid.Resources>
                                        <Style x:Key="RectangleStyle" TargetType="Rectangle">
                                            <Setter Property="Height" Value="5" />
                                            <Setter Property="Width" Value="5" />
                                            <Setter Property="Fill" Value="Black" />
                                            <Setter Property="Margin" Value="1" />
                                        </Style>
                                        <Style x:Key="RectLStyle" TargetType="Rectangle" BasedOn="{StaticResource RectangleStyle}">
                                            <Setter Property="Margin" Value="1" />
                                        </Style>
                                        <Style x:Key="RectMStyle" TargetType="Rectangle" BasedOn="{StaticResource RectangleStyle}">
                                            <Setter Property="Margin" Value="1,1,-0.5,1" />
                                        </Style>
                                        <Style x:Key="RectRStyle" TargetType="Rectangle" BasedOn="{StaticResource RectangleStyle}">
                                            <Setter Property="Margin" Value="-0.5,1,1,1" />
                                        </Style>
                                    </UniformGrid.Resources>
                                    <Rectangle Style="{DynamicResource RectLStyle}" />
                                    <Rectangle Style="{DynamicResource RectMStyle}" />
                                    <Rectangle Style="{DynamicResource RectRStyle}" />
                                    <Rectangle Style="{DynamicResource RectLStyle}" />
                                    <Rectangle Style="{DynamicResource RectMStyle}" />
                                    <Rectangle Style="{DynamicResource RectRStyle}" />
                                    <Rectangle Style="{DynamicResource RectLStyle}" />
                                    <Rectangle Style="{DynamicResource RectMStyle}" />
                                    <Rectangle Style="{DynamicResource RectRStyle}" />
                                </UniformGrid>
                            </Grid>
                        </Setter.Value>
                    </Setter>
                </Trigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>

    <StackPanel Margin="5" VerticalAlignment="Center">
        <Expander Name="expSearchSettings">
            <Expander.HeaderTemplate>
                <DataTemplate>
                    <TextBlock FontWeight="Bold" Text="Search settings" />
                </DataTemplate>
            </Expander.HeaderTemplate>
        </Expander>
        <StackPanel Margin="23,2" Orientation="Vertical" IsEnabled="{Binding ElementName=expSearchSettings, Path=IsExpanded}">
            <StackPanel Name="stkSettings" Orientation="Horizontal">
                <CheckBox Name="chkSubDirectorySearch" Content="Sub-directories?" 
                          IsChecked="{Binding AppSettings.SearchSettings.SearchSubDirectories, Mode=TwoWay}" />
                <CheckBox Name="chkAllowRepeat" Content="_Allow repeat?" 
                          IsChecked="{Binding AppSettings.SearchSettings.AllowRepeat, Mode=TwoWay}" ToolTip="Include those already played" />
                <CheckBox Name="chkIncludeFav" Content="Favourites?" 
                          IsChecked="{Binding AppSettings.SearchSettings.IncludeFavourites, Mode=TwoWay}" ToolTip="Include favourites?">
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="Checked">
                            <i:InvokeCommandAction Command="{Binding IncludeFavCheckedCommand}" />
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                </CheckBox>
                <CheckBox Name="chkBringToTop" Content="T_o top?" 
                          IsChecked="{Binding AppSettings.SearchSettings.AddFilesOnTop, Mode=TwoWay}" ToolTip="Move existing file to top?" />
                <CheckBox Name="chkAuto" Content="Auto?" 
                          IsChecked="{Binding AppSettings.SearchSettings.AutoSearch, Mode=TwoWay}" ToolTip="Move to next automatically?&#x0a;(only after Rename/Delete)" />
            </StackPanel>
            <StackPanel Name="stkSettingsCache" Orientation="Horizontal">
                <TextBox VerticalAlignment="Center" Text="{Binding AppSettings.SearchSettings.CacheLimit, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                <CheckBox Content="Auto-cache?" IsChecked="{Binding AppSettings.SearchSettings.AutoCache, Mode=TwoWay}" />
                <CheckBox Content="Cache data?" IsChecked="{Binding AppSettings.SearchSettings.CacheSearch, Mode=TwoWay}" />
            </StackPanel>
            <StackPanel Name="stkSettingsFilter" Orientation="Horizontal">
                <CheckBox Name="chkFilterFileType" Content="Filters?" 
                          IsChecked="{Binding AppSettings.SearchSettings.ApplyFilters, Mode=TwoWay}" ToolTip="Apply filters?">
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="Checked">
                            <i:InvokeCommandAction Command="{Binding FilterFileTypeCheckedCommand}" />
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                </CheckBox>
                <ComboBox Name="cmbFilters" Width="140" IsEnabled="{Binding ElementName=chkFilterFileType, Path=IsChecked}"
                          ItemsSource="{Binding AllFilters}" SelectedItem="{Binding SelectedFilter}" ToolTip="{Binding FiltersToolTip, TargetNullValue='Select filters'}">
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="DropDownOpened">
                            <i:InvokeCommandAction Command="{Binding FiltersDropDownOpenedCommand}" />
                        </i:EventTrigger>
                        <i:EventTrigger EventName="DropDownClosed">
                            <i:InvokeCommandAction Command="{Binding FiltersDropDownClosedCommand}" />
                        </i:EventTrigger>
                        <i:EventTrigger EventName="SelectionChanged">
                            <i:InvokeCommandAction Command="{Binding FiltersSelectionChangedCommand}" />
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <Grid>
                                <TextBlock Text="{Binding FileExtn}" Visibility="{Binding IsDefault, Converter={StaticResource VisibilityConverter}}" />
                                <CheckBox IsChecked="{Binding IsSelected, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
                                          Visibility="{Binding IsDefault, Converter={StaticResource VisibilityConverter}, ConverterParameter=-}">
                                    <TextBlock>
                                        <TextBlock.Text>
                                            <MultiBinding StringFormat="{}{0} | {1}">
                                                <Binding Path="FileExtn"/>
                                                <Binding Path="Count"/>
                                            </MultiBinding>
                                        </TextBlock.Text>
                                    </TextBlock>
                                </CheckBox>
                            </Grid>
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                </ComboBox>
                <Button Name="btnRefreshFilters" IsEnabled="{Binding ElementName=chkFilterFileType, Path=IsChecked}"
                        Content="F5" Command="{Binding RefreshFiltersCommand}" />

                <TextBlock Margin="30,0,0,0" VerticalAlignment="Center" FontWeight="Bold" Text="Select:" IsEnabled="{Binding ElementName=chkFilterFileType, Path=IsChecked}" />
                <Button Name="btnAll" Content="All" Command="{Binding FilterAllCommand}" IsEnabled="{Binding ElementName=chkFilterFileType, Path=IsChecked}" />
                <Button Name="btnNone" Content="None" Command="{Binding FilterNoneCommand}" IsEnabled="{Binding ElementName=chkFilterFileType, Path=IsChecked}" />
            </StackPanel>
        </StackPanel>

        <Expander Name="expPlaySettings">
            <Expander.HeaderTemplate>
                <DataTemplate>
                    <TextBlock FontWeight="Bold" Text="Play settings" />
                </DataTemplate>
            </Expander.HeaderTemplate>
        </Expander>
        <StackPanel Margin="23,2" Orientation="Horizontal" IsEnabled="{Binding ElementName=expPlaySettings, Path=IsExpanded}">
            <ComboBox Name="cmbMediaPlayer" Width="130" ItemsSource="{Binding AllMediaPlayers}" SelectedValuePath="Key" 
                      SelectedValue="{Binding AppSettings.PlaySettings.MediaPlayer, Mode=TwoWay}" 
                      ToolTip="{Binding ElementName=cmbMediaPlayer, Path=SelectedItem.Value}">
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Key, Converter={StaticResource FriendlyNameConverter}, ConverterParameter={x:Type main:eMediaPlayer}}" ToolTip="{Binding Value}" />
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>
            <CheckBox Name="chkPlayFullscreen" Content="Play _fullscreen?" 
                      IsChecked="{Binding AppSettings.PlaySettings.PlayFullscreen, Mode=TwoWay}" ToolTip="Play in fullscreen?" />
            <CheckBox Name="chkAdminNoPlay" Content="NO PLAY" Foreground="Red" IsChecked="{Binding IsAdminNoPlay, Mode=TwoWay}" />
        </StackPanel>

        <Expander Name="expFavouritesSettings">
            <Expander.HeaderTemplate>
                <DataTemplate>
                    <TextBlock FontWeight="Bold" Text="Favourites settings" />
                </DataTemplate>
            </Expander.HeaderTemplate>
        </Expander>
        <StackPanel Name="stkFavOption" Margin="23,2" Orientation="Horizontal" IsEnabled="{Binding ElementName=expFavouritesSettings, Path=IsExpanded}">
            <ComboBox Name="cmbFavOption" Width="130" IsEnabled="False" 
                      ItemsSource="{Binding AllFavouritesOptions}" SelectedValuePath="Key" 
                      SelectedValue="{Binding AppSettings.FavouritesSettings.FavouritesSaveOption, Mode=TwoWay}" 
                      ToolTip="{Binding ElementName=cmbFavOption, Path=SelectedItem.Value}">
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Key, Converter={StaticResource FriendlyNameConverter}, ConverterParameter={x:Type main:eFavouritesOption}}" ToolTip="{Binding Value}" />
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>
            <CheckBox Name="chkIncludeFavRepeat" Content="Repeats?" 
                      IsChecked="{Binding RepeatFavourites, Mode=TwoWay}" ToolTip="Play those already played?" />
            <CheckBox Name="chkSubDirectoryFav" Content="Sub-dir?" 
                      IsChecked="{Binding AppSettings.FavouritesSettings.SearchSubDirectories, Mode=TwoWay}" />
            <CheckBox Name="chkLastTimestamp" Content="Last TS only?" 
                      IsChecked="{Binding AppSettings.FavouritesSettings.TakeLatestTimestamp, Mode=TwoWay}" />
            <ToggleButton Name="tglMigrate" Padding="10,0" Foreground="Red" Content="_Migrate" 
                          IsChecked="{Binding IsMigrateContextMenuOpen, Mode=TwoWay}">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="MouseEnter">
                        <i:InvokeCommandAction Command="{Binding MigrateMouseEnterCommand}" />
                    </i:EventTrigger>
                </i:Interaction.Triggers>
                <ToggleButton.ContextMenu>
                    <ContextMenu IsOpen="{Binding IsMigrateContextMenuOpen, Mode=TwoWay}">
                        <MenuItem Name="mnuFavToDisk" Header="To Disk" Command="{Binding FavToDiskCommand}" />
                        <MenuItem Name="mnuFavFileRename" IsEnabled="False" Header="Rename file" Command="{Binding FavFileRenameCommand}"  />
                    </ContextMenu>
                </ToggleButton.ContextMenu>
            </ToggleButton>
            <ToggleButton Name="tglViewType" Height="23" Width="23" HorizontalContentAlignment="Center" Style="{DynamicResource ToggleDisplayViewStyle}" 
                          IsChecked="{Binding AppSettings.FavouritesSettings.IsFavGrouped, Mode=TwoWay}"/>
        </StackPanel>

        <Expander Name="expDeleteSettings">
            <Expander.HeaderTemplate>
                <DataTemplate>
                    <TextBlock FontWeight="Bold" Text="Delete settings" />
                </DataTemplate>
            </Expander.HeaderTemplate>
        </Expander>
        <StackPanel Margin="23,2" Orientation="Horizontal" IsEnabled="{Binding ElementName=expDeleteSettings, Path=IsExpanded}">
            <ComboBox Name="cmbDeleteOption" Width="150" 
                      ItemsSource="{Binding AllDeleteOptions}" SelectedValuePath="Key" 
                      SelectedValue="{Binding AppSettings.DeleteSettings.RecycleOption, Mode=TwoWay}" 
                      ToolTip="{Binding ElementName=cmbDeleteOption, Path=SelectedItem.Value}">
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Key, Converter={StaticResource FriendlyNameConverter}, ConverterParameter={x:Type main:eRecycleOption}}" ToolTip="{Binding Value}" />
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>
        </StackPanel>
    </StackPanel>
</Window>
